<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改文章</title>
    <#include "styleandscript.ftl"/>
    <script src="https://unpkg.com/wangeditor@3.1.1/release/wangEditor.min.js"></script>
    <script type="text/javascript">
        var editor;

        function sub(form) {
            with (form) {
                gEBI("errorTitle").innerText = "";
                gEBI("errorContent").innerText = "";
                gEBI("content_").value = editor.txt.html().replace("\n", "");
                if (!validate_required(title, gEBI("errorTitle"), "标题不能为空！")) {
                    title.focus();
                    return false;
                }
                if (!validate_required(content_, gEBI("errorContent"), "内容不能为空！")) {
                    return false;
                }
                return true;
            }
        }

        $(document).ready(function () {
            var E = window.wangEditor;
            editor = new E('#toolbar','#content');
            editor.create();
            <#if blog?? && blog.content??>
                editor.txt.html('${blog.getContentSingleLine()}');
            </#if>
        })
    </script>
</head>
<body>
<#include "./header.ftl"/>
<div style="margin-top: 16px;">
    <form action="/blog/save" method="post" onsubmit="return sub(this);"
          id="blog">
        <div>
            <input class="form-control" style="display: inline;width: 90%; vertical-align: middle;" placeholder="标题"
                   name="title"
                   id="title" <#if blog??>value="${blog.title}"</#if>/>
            <input type="submit" class="btn btn-primary" style="vertical-align: middle;" value="保存"/>
        </div>
        <span class="input-error" id="errorTitle"></span>
        <div style="margin-top: 16px;" id="toolbar"></div>
        <div style="min-height: 500px;" id="content"></div>
        <span id="errorContent" class="input-error"></span>
        <input type="hidden" id="id" name="id" value="<#if blog??>${blog.id}<#else>0</#if>"/>
        <input type="hidden" id="content_" name="content"/>
        <span class="error"><#if msg??>${msg}</#if></span>
    </form>
</div>
</body>
</html>